home *** CD-ROM | disk | FTP | other *** search
/ Borland JBuilder 6 / jbuilder6.iso / Taiji Applet Pack v2.7 / Graph / Graph.class (.txt) < prev    next >
Encoding:
Java Class File  |  2001-11-06  |  9.7 KB  |  404 lines

  1. import java.applet.Applet;
  2. import java.awt.Color;
  3. import java.awt.Component;
  4. import java.awt.Container;
  5. import java.awt.Cursor;
  6. import java.awt.Event;
  7. import java.awt.Font;
  8. import java.awt.FontMetrics;
  9. import java.awt.Graphics;
  10. import java.awt.Image;
  11. import java.awt.LayoutManager;
  12. import java.awt.event.MouseEvent;
  13. import java.awt.event.MouseListener;
  14. import java.io.BufferedReader;
  15. import java.io.IOException;
  16. import java.io.InputStream;
  17. import java.io.InputStreamReader;
  18. import java.net.MalformedURLException;
  19. import java.net.URL;
  20. import java.net.URLEncoder;
  21.  
  22. public class Graph extends Applet implements MouseListener {
  23.    // $FF: renamed from: wi int
  24.    private int field_0;
  25.    // $FF: renamed from: he int
  26.    private int field_1;
  27.    private int NCol;
  28.    private int NRow;
  29.    private float[][] data;
  30.    private Color backColor;
  31.    private String statusBarText;
  32.    private String link;
  33.    // $FF: renamed from: b java.awt.Graphics
  34.    private Graphics field_2;
  35.    private Image buffer;
  36.    private String xLabel;
  37.    private String yLabel;
  38.    private String title;
  39.    private final Color[] colors;
  40.    private float xmin;
  41.    private float xmax;
  42.    private float ymin;
  43.    private float ymax;
  44.    private boolean linked;
  45.    private int border;
  46.    private Color borderColor;
  47.  
  48.    public String getAppletInfo() {
  49.       return "Name: Graph\r\nAuthor: Taiji Software";
  50.    }
  51.  
  52.    public void register() {
  53.       try {
  54.          URL u = new URL("http://www.taijisoftware.com");
  55.          ((Applet)this).getAppletContext().showDocument(u, "_blank");
  56.       } catch (Exception e) {
  57.          System.out.println(e);
  58.          this.stop();
  59.       }
  60.    }
  61.  
  62.    public void init() {
  63.       String codeBase = null;
  64.  
  65.       try {
  66.          codeBase = (new URL(((Applet)this).getCodeBase().toString())).getHost();
  67.          System.out.println("Copyright 1999, 2001 Taiji Software(tm)\nYour domain name is : " + codeBase);
  68.          codeBase = codeBase.toUpperCase();
  69.       } catch (Exception var9) {
  70.       }
  71.  
  72.       if (!((Applet)this).getCodeBase().toString().toUpperCase().startsWith("FILE") || ((Applet)this).getParameter("debug") != null) {
  73.          String regCode = ((Applet)this).getParameter("registration_code");
  74.          if (regCode == null) {
  75.             regCode = ((Applet)this).getParameter("reg_domain");
  76.             if (regCode == null) {
  77.                this.register();
  78.             } else {
  79.                if (regCode.length() == codeBase.length() + 4 && !codeBase.startsWith("WWW.")) {
  80.                   codeBase = "WWW." + codeBase;
  81.                } else if (regCode.length() == codeBase.length() - 4 && codeBase.startsWith("WWW.")) {
  82.                   codeBase = codeBase.substring(4);
  83.                }
  84.  
  85.                char[] chars = new char[codeBase.length()];
  86.                codeBase.getChars(0, codeBase.length(), chars, 0);
  87.                String key = new String("haricot");
  88.                char[] chars2 = new char[key.length()];
  89.                key.getChars(0, key.length(), chars2, 0);
  90.  
  91.                for(int i = 0; i < codeBase.length(); ++i) {
  92.                   int j;
  93.                   if (i >= key.length()) {
  94.                      j = i - key.length() * (i / key.length());
  95.                   } else {
  96.                      j = i;
  97.                   }
  98.  
  99.                   chars[i] += chars2[j];
  100.                   chars[i] = (char)(chars[i] - chars[i] / 26 * 26 + 97);
  101.                }
  102.  
  103.                String res = new String(chars);
  104.                if (!res.equalsIgnoreCase(regCode)) {
  105.                   this.register();
  106.                }
  107.             }
  108.          } else if (!regCode.equals("settevercsedegnamiaj") && !regCode.equals("8078")) {
  109.             this.register();
  110.          }
  111.       }
  112.  
  113.       this.getParameters();
  114.  
  115.       try {
  116.          String s = "";
  117.          InputStream in = null;
  118.          in = (new URL(((Applet)this).getCodeBase(), ((Applet)this).getParameter("data_file"))).openStream();
  119.          BufferedReader br = new BufferedReader(new InputStreamReader(in));
  120.  
  121.          while((s = br.readLine()) != null) {
  122.             try {
  123.                if (this.NCol == 0) {
  124.                   int p;
  125.                   while((p = s.indexOf(" ")) != -1) {
  126.                      ++this.NCol;
  127.                      s = s.substring(p + 1);
  128.                   }
  129.  
  130.                   ++this.NCol;
  131.                }
  132.  
  133.                ++this.NRow;
  134.             } catch (Exception var12) {
  135.             }
  136.          }
  137.  
  138.          br.close();
  139.       } catch (IOException e) {
  140.          System.out.println("data file read error !" + e);
  141.       }
  142.  
  143.       ((Component)this).setBackground(this.backColor);
  144.       this.data = new float[this.NRow][this.NCol];
  145.  
  146.       try {
  147.          String s = "";
  148.          InputStream in = null;
  149.          in = (new URL(((Applet)this).getCodeBase(), ((Applet)this).getParameter("data_file"))).openStream();
  150.          BufferedReader br = new BufferedReader(new InputStreamReader(in));
  151.          int i = 0;
  152.  
  153.          while(true) {
  154.             s = br.readLine();
  155.             if (s == null) {
  156.                br.close();
  157.                break;
  158.             }
  159.  
  160.             try {
  161.                for(int j = 0; j < this.NCol - 1; ++j) {
  162.                   int p = s.indexOf(" ");
  163.                   this.data[i][j] = Float.valueOf(s.substring(0, p));
  164.                   s = s.substring(p + 1);
  165.                }
  166.  
  167.                this.data[i][this.NCol - 1] = Float.valueOf(s);
  168.             } catch (Exception var10) {
  169.             }
  170.  
  171.             ++i;
  172.          }
  173.       } catch (IOException e) {
  174.          System.out.println("data file read error !" + e);
  175.       }
  176.  
  177.       this.xmin = 0.0F;
  178.       this.xmax = 0.0F;
  179.       this.ymin = 0.0F;
  180.       this.ymax = 0.0F;
  181.  
  182.       for(int i = 0; i < this.NRow; ++i) {
  183.          if (this.data[i][0] < this.xmin) {
  184.             this.xmin = this.data[i][0];
  185.          }
  186.  
  187.          if (this.data[i][0] > this.xmax) {
  188.             this.xmax = this.data[i][0];
  189.          }
  190.  
  191.          for(int j = 1; j < this.NCol; ++j) {
  192.             if (this.data[i][j] < this.ymin) {
  193.                this.ymin = this.data[i][j];
  194.             }
  195.  
  196.             if (this.data[i][j] > this.ymax) {
  197.                this.ymax = this.data[i][j];
  198.             }
  199.          }
  200.       }
  201.  
  202.       String s = ((Applet)this).getParameter("xmin");
  203.       if (s != null) {
  204.          this.xmin = Float.valueOf(s);
  205.       }
  206.  
  207.       s = ((Applet)this).getParameter("ymin");
  208.       if (s != null) {
  209.          this.ymin = Float.valueOf(s);
  210.       }
  211.  
  212.       ((Container)this).setLayout((LayoutManager)null);
  213.       this.buffer = ((Component)this).createImage(this.field_0, this.field_1);
  214.       this.field_2 = this.buffer.getGraphics();
  215.       ((Component)this).repaint();
  216.    }
  217.  
  218.    public void update(Graphics g) {
  219.       this.paint(g);
  220.    }
  221.  
  222.    public void paint(Graphics g) {
  223.       if (this.border > 0) {
  224.          this.field_2.setColor(this.borderColor);
  225.  
  226.          for(int i = 0; i < this.border; ++i) {
  227.             this.field_2.drawRect(i, i, this.field_0 - 2 * i - 1, this.field_1 - 2 * i - 1);
  228.          }
  229.       }
  230.  
  231.       int x0 = (int)((double)this.field_0 / (double)10.0F);
  232.       int y0 = this.field_1 - (int)((double)this.field_1 / (double)10.0F);
  233.       this.field_2.setColor(Color.black);
  234.       this.field_2.drawLine(x0, y0, this.field_0 - x0, y0);
  235.       this.field_2.drawLine(x0 + 1, y0 + 1, this.field_0 - x0, y0 + 1);
  236.       this.field_2.drawLine(x0, y0, x0, this.field_1 - y0);
  237.       this.field_2.drawLine(x0 + 1, y0 + 1, x0 + 1, this.field_1 - y0);
  238.       Font f = this.field_2.getFont();
  239.       this.field_2.setFont(new Font("TimesRoman", 1, this.field_1 - y0));
  240.       FontMetrics fm = this.field_2.getFontMetrics();
  241.       int longueur = fm.stringWidth(this.title);
  242.       this.field_2.drawString(this.title, (this.field_0 - longueur) / 2, (int)((double)(this.field_1 - y0) * 0.9));
  243.       f = this.field_2.getFont();
  244.       this.field_2.setFont(new Font(f.getName(), 1, (this.field_1 - y0) / 2));
  245.       fm = this.field_2.getFontMetrics();
  246.       longueur = fm.stringWidth(this.xLabel);
  247.       this.field_2.drawString(this.xLabel, this.field_0 - longueur - 10, this.field_1 - (int)((double)(this.field_1 - y0) / (double)5.0F));
  248.       this.field_2.drawString(this.yLabel, 10, this.field_1 - y0 - 10);
  249.       int xb = 0;
  250.       int yb = 0;
  251.       boolean first = true;
  252.  
  253.       for(int j = 1; j < this.NCol; ++j) {
  254.          this.field_2.setColor(this.colors[j - 1]);
  255.          first = true;
  256.  
  257.          for(int i = 0; i < this.NRow; ++i) {
  258.             int x = x0 + (int)((this.data[i][0] - this.xmin) * (float)(this.field_0 - 2 * x0 - 10) / (this.xmax - this.xmin));
  259.             int y = y0 - (int)((this.data[i][j] - this.ymin) * (float)(y0 - (this.field_1 - y0) - 10) / (this.ymax - this.ymin));
  260.             this.field_2.fillOval(x - 4, y - 4, 8, 8);
  261.             if (first) {
  262.                first = false;
  263.             } else if (this.linked) {
  264.                this.field_2.drawLine(xb, yb, x, y);
  265.             }
  266.  
  267.             xb = x;
  268.             yb = y;
  269.          }
  270.       }
  271.  
  272.       this.field_2.setColor(Color.black);
  273.       this.field_2.setFont(new Font(f.getName(), 1, (int)((double)(this.field_1 - y0) * 0.3)));
  274.       fm = this.field_2.getFontMetrics();
  275.       String s = Float.toString(this.xmin);
  276.       this.field_2.drawString(s, x0 - fm.stringWidth(s) / 3, y0 + (int)((double)(this.field_1 - y0) * 0.4));
  277.       s = Float.toString(this.ymin);
  278.       this.field_2.drawString(s, x0 - (int)((double)fm.stringWidth(s) * 1.2), y0);
  279.       s = Float.toString(this.xmax);
  280.       this.field_2.drawString(s, this.field_0 - x0 - fm.stringWidth(s) / 2, y0 + (int)((double)(this.field_1 - y0) * 0.4));
  281.       s = Float.toString(this.ymax);
  282.       this.field_2.drawString(s, x0 - (int)((double)fm.stringWidth(s) * 1.2), (int)((double)(this.field_1 - y0) * 1.2));
  283.       g.drawImage(this.buffer, 0, 0, this);
  284.    }
  285.  
  286.    public void stop() {
  287.    }
  288.  
  289.    public void getParameters() {
  290.       this.field_0 = ((Component)this).getSize().width;
  291.       this.field_1 = ((Component)this).getSize().height;
  292.       if (this.getColor("background_color") != null) {
  293.          this.backColor = this.getColor("background_color");
  294.       }
  295.  
  296.       this.link = ((Applet)this).getParameter("link");
  297.       this.statusBarText = ((Applet)this).getParameter("status_bar_text");
  298.       this.xLabel = ((Applet)this).getParameter("xlabel_title");
  299.       this.yLabel = ((Applet)this).getParameter("ylabel_title");
  300.       this.title = ((Applet)this).getParameter("title");
  301.       if (((Applet)this).getParameter("linked").equals("yes")) {
  302.          this.linked = true;
  303.       }
  304.  
  305.       String s = ((Applet)this).getParameter("border");
  306.       if (s != null) {
  307.          this.border = Integer.parseInt(s);
  308.       }
  309.  
  310.       if (this.getColor("border_color") != null) {
  311.          this.borderColor = this.getColor("border_color");
  312.       }
  313.  
  314.    }
  315.  
  316.    private Color getColor(String param) {
  317.       String s = ((Applet)this).getParameter(param);
  318.       if (s != null) {
  319.          if (s.substring(0, 1).equals("#")) {
  320.             s = s.substring(1);
  321.             int i = Integer.parseInt(s, 16);
  322.             return new Color(i);
  323.          } else {
  324.             return null;
  325.          }
  326.       } else {
  327.          return null;
  328.       }
  329.    }
  330.  
  331.    public boolean action(Event evt, Object obj) {
  332.       return true;
  333.    }
  334.  
  335.    public URL giveURL(String url) {
  336.       try {
  337.          if (url.toUpperCase().startsWith("HTTP")) {
  338.             return new URL(url);
  339.          } else if (url.toUpperCase().startsWith("FTP")) {
  340.             int p = url.indexOf(":");
  341.             int p2 = url.indexOf(":", p + 1);
  342.             if (p2 != -1) {
  343.                url = url.substring(0, p + 3) + URLEncoder.encode(url.substring(p + 3, url.length()));
  344.             }
  345.  
  346.             p = url.indexOf("%40");
  347.             if (p != -1) {
  348.                url = url.substring(0, p) + "@" + url.substring(p + 3, url.length());
  349.             }
  350.  
  351.             return new URL(url);
  352.          } else {
  353.             return new URL(((Applet)this).getCodeBase(), url);
  354.          }
  355.       } catch (MalformedURLException e) {
  356.          System.out.println(e);
  357.          return null;
  358.       }
  359.    }
  360.  
  361.    public Graph() {
  362.       this.colors = new Color[]{Color.blue, Color.red, Color.yellow, Color.green, Color.black};
  363.       this.backColor = Color.white;
  364.       ((Component)this).addMouseListener(this);
  365.    }
  366.  
  367.    public void mouseClicked(MouseEvent e) {
  368.    }
  369.  
  370.    public void mouseEntered(MouseEvent e) {
  371.       if (this.statusBarText != null) {
  372.          ((Applet)this).showStatus(this.statusBarText);
  373.       }
  374.  
  375.       if (this.link != null) {
  376.          ((Component)this).setCursor(new Cursor(12));
  377.       }
  378.  
  379.    }
  380.  
  381.    public void mouseExited(MouseEvent e) {
  382.       if (this.link != null) {
  383.          ((Component)this).setCursor(new Cursor(0));
  384.       }
  385.  
  386.    }
  387.  
  388.    public void mousePressed(MouseEvent e) {
  389.       if (this.link != null) {
  390.          String target = ((Applet)this).getParameter("target");
  391.          if (target == null) {
  392.             target = "_blank";
  393.          }
  394.  
  395.          URL u = this.giveURL(this.link);
  396.          ((Applet)this).getAppletContext().showDocument(u, target);
  397.       }
  398.  
  399.    }
  400.  
  401.    public void mouseReleased(MouseEvent e) {
  402.    }
  403. }
  404.